﻿using System.ComponentModel;
using Om.Camera;
using Om.Camera.ATH1010_25;
using Om.Camera.Normal;
using Om.Camera.Toup;
using Om.Core.Device;
using Om.Core.Extension;

namespace Om.Core.Singleton;

public class DevicesManager : SingletonBase<DevicesManager>
{
    private DevicesConfig _config => DevicesConfig.Instance;


    public Ptz.Ptz Ptz { get; set; } = new Ptz.Ptz();
    public SignalGenerator Signal { get; set; } = new SignalGenerator();

    /// <summary>
    /// 获取相机
    /// key:description, value:camera
    /// </summary>
    /// <returns></returns>
    public Dictionary<string,IBaseCamera> GetBaseCameras()
    {
        try
        {
            var list = new Dictionary<string, IBaseCamera>();
            var props = typeof(DevicesManager).GetProperties();
            foreach (var prop in props)
            {
                if (!typeof(IBaseCamera).IsAssignableFrom(prop.PropertyType))
                    continue;

                var baseCamera = prop.GetValue(Instance) as IBaseCamera;
                if (baseCamera == null) continue;
                var desc = prop.GetDescriptionOrName();
                list.Add(desc, baseCamera);
                CameraDescAndName[desc] = prop.Name;
            }

            return list;
        }
        catch (Exception e)
        {
            LogHelper.Log(e);
            throw;
        }
    }
    /// <summary>
    /// 获取相机描述获取属性名
    /// </summary>
    /// <param name="description"></param>
    /// <returns></returns>
    public string GetCameraName(string description)
    {
        return CameraDescAndName[description];
    }

    private Dictionary<string,string> CameraDescAndName = new Dictionary<string, string>();


    /// <summary>
    /// 长波热像仪
    /// </summary>
    [Description("长波热像仪")]
    public IrCamera IrCamera { get; set; } = new IrCamera();

    /// <summary>
    /// 偏振相机
    /// </summary>
    [Description("偏振相机")]
    public SpinnakerCamera SpinnakerCamera { get; set; } = new SpinnakerCamera();
    /// <summary>
    /// 短波相机
    /// </summary>
    [Description("短波相机")]
    public VkCamera VkShortCamera { get; set; } = new VkCamera();
    /// <summary>
    /// 中波相机
    /// </summary>
    [Description("中波相机")]
    public VkCamera VkMidCamera { get; set; } = new VkCamera();
    /// <summary>
    /// 可见光近红外相机
    /// </summary>
    [Description("近红外相机")]
    public ToupCamera ToupCamera { get; set; } = new ToupCamera();
    /// <summary>
    /// 可见光近红外高光谱相机
    /// </summary>
    [Description("近红外高光谱")]
    public NormalCamera HyperspectralCamera { get; set; } = new NormalCamera();
    /// <summary>
    /// 短波红外高光谱
    /// </summary>
    [Description("短波红外高光谱")]
    public AthCamera AthCamera { get; set; } = new AthCamera();
}